package com.sinosoft.demo2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DB2Demo {
    public static void main(String[] args) {
        // JDBC连接参数
        String jdbcUrl = "jdbc:db2://10.146.33.43:50001/sqs0819";
        String user = "db2inst2";
        String password = "db2inst2";

        // 连接到数据库
        Connection connection = null;
        try {
            // 加载DB2 JDBC驱动程序
            Class.forName("com.ibm.db2.jcc.DB2Driver");

            // 创建连接
            connection = DriverManager.getConnection(jdbcUrl, user, password);

            // 如果连接成功，打印成功信息
            if (connection != null) {
                System.out.println("DB2 JDBC连接成功！");
            } else {
                System.out.println("DB2 JDBC连接失败！");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("DB2 JDBC连接失败！");
        } finally {
            // 关闭数据库连接
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
